CLIP.Search.enc = function(val) {
	return val.replace(/ /g, '-');
};

CLIP.Search.dec = function(val) {
	return val.replace(/-/g, ' ');
};

CLIP.Clips.initPage = 1;
CLIP.Clips.currentPage = 1;
CLIP.Clips.pageSize = 15;

CLIP.Clips.searchUrl = function(keyword) {
	return 'http://phim3s.net/search/' + keyword + '/page-' + CLIP.Clips.currentPage + '/';
};

CLIP.Clips.filterUrl = function() {
	return 'http://phim3s.net/danh-sach/' + $('#types input:checked').val() + '/page-' + CLIP.Clips.currentPage + '/?order_by=' + $('#sorts input:checked').val() + '&category_id='
			+ $('#cats input:checked').val();
};

CLIP.Clips.moreHtml = function(text) {
	var html = [];

	text = bum.util.parse(text, '<ul class="list-film">', '</ul><div><span class="page_nav">');
	if (text == null) {
		return html;
	}
	$.each(text.split('<li><div class="inner">'), function(i, clip) {
		if (i > 0) {
			++CLIP.Clips.moreCount;
			var code = bum.util.parse(clip, '<a href="', '"');
			var title = bum.util.parse(clip, 'title="', '"');
			var originalTitle = bum.util.parse(clip, '<div class="name2">', '</div>');
			var img = bum.util.parse(clip, '<img src="', '"');

			html.push('<a class="item clip" href="#" code="', code, '"><div class="cw">');
			html.push('<img src="http://cdn.bum.vn/_.gif" style="background-image:url(', img, ');"/>');
			html.push('<div class="iw"><h4>', title, '</h4>');
			html.push('<h5>', originalTitle, '</h5></div>');
			html.push('</div></a>');
		}
	});

	return html;
};

CLIP.Info.infoUrl = function(code) {
	bum.api.fetchUrl('http://phim3s.net/' + code + 'xem-phim/', CLIP.Chap.headers, CLIP.Info.getChaps);

	return 'http://phim3s.net/' + code;
};

CLIP.Info.parseInfo = function(text) {
	text = bum.util.parse(text, '<div class="blockbody">', '<div class="tags">');
	if (text == null) {
		return null;
	}

	var poster = bum.util.parse(text, '<img src="', '"');
	var title = bum.util.parse(text, '<h2 class="title fr">', '</h2>');
	var originalTitle = bum.util.parse(text, '<div class="name2 fr"><h3>', '</h3>');
	var detail = bum.util.parse(text, '<div class="dinfo">', '<dl class="col2">');
	if (detail) {
		detail = detail.replace(/<a /g, '<span ').replace(/<\/a>/g, '<\/span>');
	}
	var intro = bum.util.parse(text, '<div class="tab text">', '<div id="abd_vidinpage">').replace(/<[\/]{0,1}(iframe|a)[^><]*>/gi, "").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
			'');

	var clip = {
		poster : poster,
		title : title,
		originalTitle : originalTitle,
		detail : detail,
		intro : intro
	};

	return clip;
};

// phim3s only
CLIP.Info.getChaps = function(text) {
	var html = [];

	text = bum.util.parse(text, '<div class="serverlist">', '</div></div></div></div>').replace(/data-type="watch" /g, '');
	$.each(text.split('<div class="server"><div class="label"><i></i>'), function(i, list) {
		if (i > 0 && list.indexOf('Download') === -1) {
			// var name = bum.util.parse(list, '" />', '</div>');
			list = bum.util.parse(list, '<li>', '</ul>').replace(/<[\/]?li>/g, '');
			html.push('<div>', list, '</div>');
		}
	});

	var T = $('#chaps');
	if (T.length > 0) {
		$('#chaps').html(html.join(''));
	} else {
		CLIP.Chap.chaps = html.join('');
	}
};

CLIP.Chap.headers = [ 'Accept', 'text/plain, text/html', 'Host', 'phim3s.net', 'Cache-Control', 'max-age=0', 'Connection', 'close', 'User-Agent',
		'Mozilla/5.0 (Linux; U; Android 2.2; en-us; DROID2 GLOBAL Build/S273) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' ].join('|');

CLIP.Chap.chapUrl = function(code) {
	return 'http://phim3s.net/' + code;
};
// custome
CLIP.Chap.streamUrl = function(text) {
	return bum.util.parse(text, '_video_url = "', '"');
};